package com.mall.manager.FirstGardenStatistics.service;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.mall.untils.DateUtil;
/**
 * @全国园所首次登录统计
 * @author liugb
 * @Date 2016 7 13
 */
@Service
public class FirstGardenStatisticsService {
	@Resource
    private JdbcTemplate jdbcTemplate;
	//日志信息
	private Logger logger = LoggerFactory.getLogger(FirstGardenStatisticsService.class);	
	/**
	 * @全国园所首次登录统计
	 * @param request
	 * @return
	 */
	public List<Map<String, Object>> manager_firstGarden_list(Map<String, Object> paraMap1) {
		try {
			String create_time = MapUtils.getString(paraMap1, "create_time");
			if(create_time == null || create_time.equals(" ")){
				create_time = DateUtil.getYesterdayString();
			}
			String sql = "select * from db_processing.t_first_garden_statistics where date_format(create_time,'%Y-%m-%d') = ?";
			List<Map<String, Object>> queryForlist = jdbcTemplate.queryForList(sql,create_time);
			return queryForlist;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			logger.debug(e.getMessage());
			return null;
		}
	}
	/**
     * @全国园所首次登录统计增加
     * @param paraMap
     * @return
     */
	public int manager_insert_firstgarden(Map<String, Object> paraMap) {
		String g_number = MapUtils.getString(paraMap, "g_number");
		String area_id = MapUtils.getString(paraMap, "area_id");
		String all_time = MapUtils.getString(paraMap, "all_time");
		try {
			String sql="insert into db_processing.t_first_garden_statistics(id,g_number,area_id,all_time,create_time,update_time) values(?,?,?,?,now(),now())";
			int update = jdbcTemplate.update(sql,g_number,area_id,all_time);
			return update;
		} catch (Exception e) {
			return 0;
		}
	}
	
}
